//关闭
function closeDiscount(){
	window.location.href=ctx+"/project/discount/list";
} 
$(document).ready(function(){
	//全选/取消全部 
	$("#checkboxAll").click(function() { 
		if (this.checked == true) { 
			$("input[name='product_name']").each(function() { 
				this.checked = true; 
			}); 
		} else { 
			$("input[name='product_name']").each(function() { 
				this.checked = false; 
			}); 
		} 
	});
});

//保存0
//保存关闭1
function saveDiscount(state){
	var disCountPlanName=$("#disCountPlanName").val();
	var status=$("#status").val();
	if(disCountPlanName==""){
		showAlertDialog({msg:'折扣方案名称不能为空！'});
		return;
	}
	var projGUID=$("#projGUID").val();
	
	var tb=document.getElementById("discountDefine_table");//获取table对像
	var rows=tb.rows;
	if(rows.length==1){
		showAlertDialog({msg:'方案中至少要有一条折扣明细!'});
		return;
	}
   
	var calRule=$("#calRule").val();
	if(calRule==""){
		showAlertDialog({msg:'请编辑"折扣总价计算规则" '});
		return;
	}
	$.ajax({
		url: ctx+"/project/discount/saveDiscountPlan",
		type:'POST',
		dataType: "json",
		data:{ 
			disCountPlanName:disCountPlanName,
			status:status,
			projGUID:projGUID,
			calRule:calRule
		},
		success:function(data){
			if(data.success=="true"){
				showAlertDialog({msg:'保存成功'});
				if(state==1){
					closeDiscount();
				}
			}else{
				showAlertDialog({msg:data.msg});
				return;
			}
		},
		error:function(){
			showAlertDialog({msg:'新建失败'});
		}
	});
}
